import 'package:flutter/material.dart';
import 'package:hospitable_rental/pages/home/search/room_item.dart';
import 'package:hospitable_rental/routes/routes.dart';
import 'package:hospitable_rental/widgets/common_image.dart';
import 'package:hospitable_rental/widgets/common_tags.dart';

class RoomItemWidget extends StatelessWidget {
  final RoomItem item;

  const RoomItemWidget(
    this.item, {
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => Navigator.of(context).pushNamed(Routes.roomDetail + "/${item.id}"),
      behavior: HitTestBehavior.translucent,
      child: Container(
        margin: EdgeInsets.only(left: 10.0, right: 10.0, bottom: 10.0),
        child: Row(
          children: [
            CommonImage(
              item.imageUri.toString(),
              width: 132.0,
              height: 100.0,
            ),
            SizedBox(width: 10.0),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    item.title.toString(),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontWeight: FontWeight.w600),
                  ),
                  SizedBox(height: 5.0),
                  Text(item.subtitle.toString()),
                  SizedBox(height: 5.0),
                  if (item.tags != null)
                    Wrap(
                      children: item.tags!
                          .map(
                            (tag) => CommonTags(tag),
                          )
                          .toList(),
                    ),
                  SizedBox(height: 5.0),
                  Text(
                    "${item.price} 元/月",
                    style: TextStyle(
                      color: Colors.orange,
                      fontSize: 16.0,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
